package com.timesheet.server.core.mapper;

import java.lang.reflect.Field;

public class Mapper2 {

	public static Object map(Object to, Object from) {

		Class<? extends Object> toObject = to.getClass();

		Class<? extends Object> fromObject = from.getClass();

		Field[] toDeclaredFields = toObject.getDeclaredFields();
		Field[] fromDeclaredFields2 = fromObject.getDeclaredFields();

		for (int i = 0; i < fromDeclaredFields2.length; i++) {

			Field field1 = toDeclaredFields[i];
			field1.setAccessible(true);

			Field field2 = fromDeclaredFields2[i];
			field2.setAccessible(true);

			for (Field field : toDeclaredFields) {

				if (field.getName().equals(field2.getName()) && !field.getName().equals("serialVersionUID")) {

					Object object;
					try {
						object = field2.get(from);
						field1.set(to, object);
					}
					catch (Exception exception) {
						exception.printStackTrace();
					}

				}
			}
		}

		return to;

	}
	
	
	
	

}